export type TrendDirection = 'up' | 'down' | 'flat';

export interface SummaryMetricItem<T = string | number> {
  value?: T;
  label?: string;
  status?: 'normal' | 'warning' | 'error';
  lastSyncAt?: string;
  changePercent?: number;
  actionText?: string;
}

export interface NetworkMetric {
  title: string;
  speed?: number;
  unit?: string;
  percent?: number;
  trend?: TrendDirection;
}

export interface VpnMetric {
  status: 'connected' | 'disconnected';
  label: string;
  duration?: string;
}

export interface NetworkHistoryItem {
  timestamp: string;
  upload: number;
  download: number;
}

export interface ResourceMetric {
  used: number;
  total: number;
  unit: string;
  percent: number;
}

export interface ResourceUsageMetrics {
  cpu: ResourceMetric;
  memory: ResourceMetric;
  disk: ResourceMetric;
}

export interface PipelineStats {
  taskCount?: number;
  orderCount?: number;
  todayFinishedSize?: number;
  thisMonthFinishedSize?: number;
  inProgressCount?: number;
  taskTrend?: TrendDirection;
  orderTrend?: TrendDirection;
  todayTrend?: TrendDirection;
  monthTrend?: TrendDirection;
  runningTrend?: TrendDirection;
}

export interface PipelineJob {
  id?: string;
  name?: string;
  typeLabel?: string;
  progress?: number;
  status?: 'processing' | 'paused' | 'stopped' | 'success';
  rangeText?: string;
  source?: string;
  description?: string;
}

export type PipelineKey = 'collect' | 'deliver' | 'receive';

export interface PipelineMetric {
  key: PipelineKey;
  label: string;
  stats?: PipelineStats;
  currentJob?: PipelineJob;
  lastJob?: PipelineJob;
}

export interface DeviceAlertMetric {
  id?: string;
  title: string;
  description?: string;
  happenAt?: string;
  severity: 'critical' | 'warning';
  levelLabel?: string;
}

export type DeviceBasicFieldKey = 'nodeName' | 'gatewayId' | 'ip' | 'group' | 'operator' | 'brand';

export interface DeviceBaseInfoMetrics {
  summary: {
    onlineStatus: SummaryMetricItem<string>;
    alerts: SummaryMetricItem<number>;
    todayDataVolume: SummaryMetricItem<string>;
    totalDatasource: SummaryMetricItem<number>;
  };
  basicInfo?: Partial<Record<DeviceBasicFieldKey, string>>;
  network: {
    upload?: NetworkMetric;
    download?: NetworkMetric;
    vpn?: VpnMetric;
    history?: NetworkHistoryItem[];
  };
  resources?: ResourceUsageMetrics;
  pipelines: {
    collect?: PipelineMetric;
    deliver?: PipelineMetric;
    receive?: PipelineMetric;
  };
  alerts?: DeviceAlertMetric[];
}

export interface NetworkDataPoint {
  date: string;
  value: number;
}

export interface DeviceMetricsApiResponse {
  memoryAvailableBytes: number;
  diskTotalBytes: number;
  networkUploadBytes: NetworkDataPoint[];
  diskUsagePercentage: number;
  memoryUsagePercentage: number;
  memoryTotalBytes: number;
  diskAvailableBytes: number;
  cpuLoadPercentage: number;
  networkDownloadBytes: NetworkDataPoint[];
  vpnStatus: number;
  vpnTime: number;
  alertCount: number;
  alertList: any[];
}
